package com.testdemo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

/**
 * Auth：yujunyao
 * Since: 2016/5/20 16:35
 * Email：yujunyao@yonglibao.com
 *
 * http://blog.csdn.net/pi9nc/article/details/9281829  这篇Blog讲的比较详细
 */
public class EventTouchActivity extends AppCompatActivity {
    private static final String TAG = "EventTouchActivity";
    private Button button1 = null;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_event_touch);
        button1 = (Button) findViewById(R.id.event_touch_btn);
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "button1---setOnClickListener");
            }
        });
        button1.setOnTouchListener(new View.OnTouchListener() {//OnTouch事件优先于OnClick事件（由此可以推断OnClick事件肯定在OnTouch方法中）
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Log.i(TAG, "button1---setOnTouchListener");
                return false;//改为true,则OnClick事件接收不到回调
            }
        });

        /**************只要触摸了任何控件，就一定会调用dispatchTouchEvent方法*****************/

        findViewById(R.id.linear_ll).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.i(TAG, "linear_ll---setOnTouchListener");
            }
        });

    }

}
